from io import BytesIO
from PIL import Image
import json
import requests
from time import time
from util import image_to_base64, base64_to_image

#发送代码
def json_send(dataPModel,url):
    headers = {"Content-type": "application/json", "Accept": "text/plain", "charset": "UTF-8"}
    response = requests.post(url=url, headers=headers, data=json.dumps(dataPModel))
    return json.loads(response.text)

if __name__ == "__main__":
    url = 'http://127.0.0.1:8520/cv/v1/obj_detect'
    img = Image.open('/home/xiaoyao/works/yolov3/AlexeyAB-darknet-master/darknet-master/data/dog.jpg')
    # print(img.size)
    img_base64 = image_to_base64(img)
    dataPModel = {"img_base64": img_base64}
    a = time()
    # for i in range(100):
    result = json_send(dataPModel, url)
    img_detect = base64_to_image(result['result']['base64'])
    img_detect.show()
